/*******************************************************************************
 * Copyright (c) 2021, 2025 Lablicate GmbH.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Philip Wenig - initial API and implementation
 *******************************************************************************/
package org.eclipse.chemclipse.model.methods;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.chemclipse.processing.DataCategory;
import org.eclipse.chemclipse.processing.methods.ProcessEntry;
import org.eclipse.chemclipse.processing.methods.ProcessEntryContainer;
import org.eclipse.chemclipse.processing.methods.ProcessMethod;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ProcessEntry_1_Test {

	private ProcessEntry processEntry;

	@BeforeEach
	public void setUp() {

		Set<DataCategory> dataCategories = new HashSet<>();
		dataCategories.add(DataCategory.MSD);
		ProcessEntryContainer processEntryContainer = new ProcessMethod(dataCategories);
		processEntry = new ProcessEntry(processEntryContainer);
	}

	@Test
	public void test1() {

		assertEquals(ProcessEntryContainer.DEFAULT_PROFILE, processEntry.getActiveProfile());
		Map<String, String> settingsMap = processEntry.getSettingsMap();
		assertEquals(0, settingsMap.size()); // Settings are created on-the-fly
	}

	@Test
	public void test2() {

		processEntry.setActiveProfile("Test");
		assertEquals("Test", processEntry.getActiveProfile());
		Map<String, String> settingsMap = processEntry.getSettingsMap();
		assertEquals(0, settingsMap.size()); // Settings are created on-the-fly
	}

	@Test
	public void test3() {

		processEntry.setActiveProfile("Test");
		processEntry.setSettings("Hello World");
		assertEquals("Hello World", processEntry.getSettings());
		Map<String, String> settingsMap1 = processEntry.getSettingsMap();
		assertEquals(1, settingsMap1.size());
		assertTrue(settingsMap1.containsKey("Test"));

		processEntry.setActiveProfile(ProcessEntryContainer.DEFAULT_PROFILE);
		processEntry.setSettings("");
		assertEquals("", processEntry.getSettings());
		Map<String, String> settingsMap2 = processEntry.getSettingsMap();
		assertEquals(2, settingsMap2.size());
		assertTrue(settingsMap2.containsKey("Test"));
		assertTrue(settingsMap2.containsKey(ProcessEntryContainer.DEFAULT_PROFILE));
	}

	@Test
	public void test4() {

		processEntry.setActiveProfile("Test");
		processEntry.setSettings("Hello World");
		assertEquals("Hello World", processEntry.getSettings());
		Map<String, String> settingsMap1 = processEntry.getSettingsMap();
		assertEquals(1, settingsMap1.size());
		assertTrue(settingsMap1.containsKey("Test"));
		processEntry.deleteProfile("Test");
		assertEquals(ProcessEntryContainer.DEFAULT_PROFILE, processEntry.getActiveProfile());

		processEntry.setActiveProfile(ProcessEntryContainer.DEFAULT_PROFILE);
		processEntry.setSettings("");
		assertEquals("", processEntry.getSettings());
		Map<String, String> settingsMap2 = processEntry.getSettingsMap();
		assertEquals(1, settingsMap2.size());
		assertFalse(settingsMap2.containsKey("Test"));
		assertTrue(settingsMap2.containsKey(ProcessEntryContainer.DEFAULT_PROFILE));
	}
}
